package com.office.controller;




import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.office.bean.Config;
import com.office.service.ConfigService;
import com.office.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("config")
@CrossOrigin
public class ConfigController {
    //依赖注入
    @Autowired
    ConfigService configService;
    @GetMapping("list")
    public Result getList(){
        List<Config> list = configService.list();
        return Result.success(list);
    }
    @PostMapping
    public Result add(@RequestBody Config config){
        configService.save(config);
        Config config1 = configService.getById(config.getId());
        return Result.success("保存成功",config);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") int id){
        boolean b = configService.removeById(id);
        if (b){
            return Result.success("删除成功");
        }
        else {
            return Result.fail(201,"删除失败");
        }
    }
    @PutMapping
    public Result edit(@RequestBody Config config){
        boolean b = configService.saveOrUpdate(config);
        Config config1 = configService.getById(config.getId());
        if (b){
            return Result.success("保存成功");
        }
        else {
            return Result.fail(201,"修改失败");
        }
    }
    @GetMapping("page")
    public Result getPage(Page page){
        Page result = configService.page(page);
        return Result.success(result);

    }
}

